package dca.sistemascontrole.sinais;

import java.util.Date;

/**
 *
 * @author Rafael
 */
public abstract class Sinal {

    protected long t0;
    protected float offset;
    protected float periodo;
    protected float amplitude;
    protected float frequencia;
    public static final int DEGRAU = 3;
    public static final int SENOIDAL = 4;
    public static final int QUADRADA = 5;
    public static final int DENTE_DE_SERRA = 6;
    public static final int ALEATORIO = 7;

    public Sinal(float periodo, float amplitude, float frequencia, float offset) {
        t0 = System.currentTimeMillis();
        this.periodo = periodo;
        this.amplitude = amplitude;
        this.frequencia = frequencia;
        this.offset = offset;
    }

    protected abstract float getValue(long t);

    public float getNextValue(long t) {
        float value = getValue(t) + offset;

        if (value > 3) {
            value = 3;
        } else if (value < -3) {
            value = -3;
        }

        return value;
    }

    public float getPeriodo() {
        return periodo;
    }

    public float getAmplitude() {
        return amplitude;
    }

    public float getFrequencia() {
        return frequencia;
    }

    public static Sinal gerarSinal(int tipoSinal, float periodo, float amplitude, float frequencia, float offset) {
        Sinal sinal;
        switch (tipoSinal) {
            case DEGRAU:
                sinal = new Degrau(amplitude, offset);
                break;
            case SENOIDAL:
                sinal = new Senoidal(periodo, amplitude, frequencia, offset);
                break;
            case QUADRADA:
                sinal = new OndaQuadrada(periodo, amplitude, frequencia, offset);
                break;
            case DENTE_DE_SERRA:
                sinal = new DenteDeSerra(periodo, amplitude, frequencia, offset);
                break;
            case ALEATORIO:
                sinal = new Aleatorio(periodo, amplitude, frequencia, offset);
                break;
            default:
                sinal = new Degrau(0, offset);
        }

        return sinal;
    }
}
